<template>
  <el-dialog
  title="题目审核"
  :visible.sync="dialogVisible"
  width="21%"
  @close="$emit('close')"
  :before-close="closeFn"
  >
  <el-form ref="form" :model="form" :rules="rules">
     <el-form-item >
    <el-radio-group v-model="form.chkState">
      <el-radio :label="1">通过</el-radio>
      <el-radio :label="2">拒绝</el-radio>
    </el-radio-group>
  </el-form-item>
   <el-form-item prop="chkRemarks">
    <el-input type="textarea" placeholder="请输入审核意见" v-model="form.chkRemarks"></el-input>
  </el-form-item>
   <el-form-item>
    <el-button @click="closeFn">取消</el-button>
    <el-button type="primary" @click="configFn" >确认</el-button>
  </el-form-item>
  </el-form>

</el-dialog>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'CHeckDiag',
  props: {
    dialogVisible: {
      type: Boolean
    },
    checkDigId: {
      type: [Number, String],
      required: true
    }
  },
  data () {
    const validateChk = (rule, value, callback) => {
      if (value.length === 0) {
        this.$message.warning('请输入审核意见')
      } else {
        callback()
      }
    }
    return {
      form: {
        chkState: 1,
        chkRemarks: ''
      },
      rules: {
        chkRemarks: [{ validator: validateChk }]
      }

    }
  },
  methods: {
    // 点击确定按钮
    configFn () {
      this.$refs.form.validate(async (valid) => {
        if (!valid) return

        const res = await choiceCheck({ id: this.checkDigId, ...this.form })
        if (res.data.success) {
          this.$message.success('你已成功审核')
        } else {
          this.$message('审核失败')
          this.$emit('close')
        }
        this.$emit('CheckChange')
      })
    },

    // 点击取消
    closeFn () {
      this.$message('你已成功取消')
      this.$emit('close')
    }
  }
}
</script>

<style>

</style>
